<template>
	<u-index-list
		:index-list="indexList"
		inactiveColor="#1a1a1a"
		activeColor="#3ba574"
		:sticky="false">
		<u-index-item v-for="(key, index) in indexList" :key="key">
			<u-index-anchor :text="key" color="#6d6d6d" bgColor="#ededed"></u-index-anchor>
			<view class="list-cell" v-for="(cell, index) in itemArr[key]">
				<u-avatar :src="cell.avatar" shape="square" size="40"></u-avatar>
				<text>{{cell.realname}}</text>
			</view>
		</u-index-item>
	</u-index-list>
</template>

<script>
	export default {
		data() {
			return {
				indexList: [],
				itemArr: {}
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			init() {
				uni.showLoading({
					title: '加载中'
				})
				uni.request({
				    url: 'http://241121-0011.demo.boywe.cn/member/list', //仅为示例，并非真实接口地址。
				    header: {
				        'Authorization': 'Bearer ' + uni.getStorageSync('Authorization')
				    },
				    success: (res) => {
						uni.hideLoading()
				        var result = res.data
						this.indexList = Object.keys(result.data).sort()
						this.itemArr = result.data
				    }
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list-cell {
		position: relative;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		width: 100%;
		padding: 10px 15px;
		overflow: hidden;
		color: #323233;
		font-size: 14px;
		line-height: 24px;
		background-color: #fff;
		text {
			margin-left: 15px;
		}
		&::after {
			position: absolute;
			content: '';
			display: block;
			right: 0;
			left: 70px;
			bottom: 0;
			height: 1px;
			background-color: #e6e6e6;
		}
		&:last-child::after {
			display: none;
		}
	}
</style>